/**
    算法描述：
    核心问题：
    解决所需数据结构+算法：
**/
#include<iostream>
using namespace std;

long long dp[205][205] = {0}, ans= -1, n, a[205];

int main() {
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        a[i+n] = a[i];
    }
    n *= 2;

    for (int len=2; len<=n; len++) {
        for (int i=1; i<=n-len+1; i++) {
            int j = i+len-1;
            for (int k=i; k<j; k++) {
                dp[i][j] = max(dp[i][j], dp[i][k] + dp[k+1][j] + a[i]*a[k+1]*a[j+1]);
            }
        }
    }

    for (int i=1; i<=n/2+1; i++) {
        ans = max(ans, dp[i][i+n-1]);
    }
    cout << ans/2;

    return 0;
}